params ["_group", "_veh", "_control"];


private _end = false;
private _target = objNull;
private _out_ed = false;

/*
if(isNull _veh)then{
	_veh = vehicle (leader _group);
};
*/

while {!_end} do
{
	if(isNull _group
	|| {count units _group == 0}) exitWith{};
	
	if(isNull _target)then{
		//寻找最近新目标
		if(_control) then{
			_target = [_veh, 2000] call fn_getPlayerNear;
			//显示玩家信息
			_group reveal _target;
		}
		else{
			_target = [_veh, 1000] call fn_getPlayerNear;//fn_getPlayerAttack;
		};
	};
	
	
	if(!isNull _target) then
	{
		//下车
		if(!_out_ed
		&& {_target distance _veh < 200}
		&& {(_group knowsAbout _target) > 2.49})then
		{
			_out_ed = true;
			_veh engineOn false;
			private _cargos = crew _veh;
			
			if((_veh isKindOf "Tank")
			|| {_veh isKindOf "Air"}) then
			{//飞机坦克，不下司机炮手指挥官
				_cargos = _cargos - [driver _veh, gunner _veh, commander _veh];
			}
			else
			{//普通除了炮手指挥官
				_cargos = _cargos - [gunner _veh, commander _veh];
			};
			
			waitUntil{Sleep 1; speed _veh < 10};
			//顺序下车太慢了
			{ unassignVehicle _x;moveOut _x; } forEach _cargos; _cargos allowGetIn false;
		};
		sleep 1;

		_veh engineOn true;
		_group move position _target;
	};
	
	Sleep 10;
};